import javax.swing.text.rtf.RTFEditorKit;

/**
 * @author 03010570
 * @date 2020/07/03
 * describe:    LeetCode : 108、讲有序数组转换为二叉搜索树    https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/
 */
public class LeetCode_108 {

    public static void main(String[] args) {
        int[] ints = {-10, -3, 0, 5, 9};
        LeetCode_108 code108 = new LeetCode_108();
        TreeNode treeNode = code108.sortedArrayToBST(ints);

    }

    public TreeNode sortedArrayToBST(int[] nums) {
        return dfs(nums, 0, nums.length - 1);
    }

    private TreeNode dfs(int[] nums, int left, int right) {
        int mid = left + (right - left) /2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = dfs(nums, left, mid - 1);
        root.right = dfs(nums, mid + 1, right);
        return root;
    }

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode(int x) { val = x; }
     * }
     */


}
